package entity;

import lombok.Data;

import java.util.*;

/**
 * 制定策略的类
 */
@Data
public class Strategy {
    /**
     * 总金额
     */
    Integer amount;
    /**
     * 当次下注金额
     */
    Integer chip;
    /**
     * 当前循环中所处步骤
     */
    Integer time;
    /**
     * 压注策略
     */
    List<Integer> bet;

    /**
     * 当前策略运行的游戏局数
     */
    int count;
    int lost;
    int win;
    int max;

    /**
     * 策略2335
     */
    public void strategy2335() {
        if (count == 0) {
            amount = 340;
            chip = 30;
            time = 12;
        }
        Random random = new Random();
        int n = random.nextInt(4);
        bet = new ArrayList<>();
        switch (n) {
            case 0:
                bet.add(0);
                bet.add(0);
                break;
            case 1:
                bet.add(0);
                bet.add(1);
                break;
            case 2:
                bet.add(1);
                bet.add(1);
                break;
            case 3:
                bet.add(1);
                bet.add(0);
                break;
        }
    }

    /**
     * 策略运行
     *
     * @param pokers 一套牌
     */
    public void run(List<Poker> pokers) {
        for (Poker poker : pokers) {
            count++;
            switch (time) {
                case 12:
                    if (poker.getWinner().equals(bet.get(0))) {
                        amount += chip;
                        chip = 50;
                        time = 13;
//                        if (amount >= 3400)
//                            time = 213;
                    } else if (!poker.getWinner().equals(bet.get(0))
                            && poker.getWinner() != 2
                            && !(poker.getWinner() == 0
                            && poker.getBankerPoint() == 6)) {
                        amount -= chip;
                        lost++;
                        strategy2335();
                        if (amount < 210) {
                            chip = 50;
                            time = 23;
                        }
                    }
                    break;
                case 13:
                    if (poker.getWinner().equals(bet.get(1))) {
                        amount += chip;
                        chip = 30;
                        time = 12;
                        win++;
                        strategy2335();
//                        if (amount >= 3400) {
//                            chip = 300;
//                            time = 213;
//                        }
                    } else if (!poker.getWinner().equals(bet.get(1))
                            && poker.getWinner() != 2
                            && !(poker.getWinner() == 0
                            && poker.getBankerPoint() == 6)) {
                        amount -= chip;
                        time = 12;
                        lost++;
                        strategy2335();
                    }
                    if (amount <= 210) {
                        chip = 50;
                        time = 23;
                    }
                    break;
                case 23:
                    if (poker.getWinner().equals(bet.get(0))) {
                        amount += chip;
                        chip = 80;
                        time = 25;
                    } else if (!poker.getWinner().equals(bet.get(0))
                            && poker.getWinner() != 2
                            && !(poker.getWinner() == 0
                            && poker.getBankerPoint() == 6)) {
                        amount -= chip;
                        time = 23;
                        lost++;
                        strategy2335();
                        if (amount <= 50)
                            return;
                    }
                    break;
                case 25:
                    if (poker.getWinner().equals(bet.get(1))) {
                        amount += chip;
                        chip = 30;
                        time = 12;
                        strategy2335();
                        win++;
                    } else if (!poker.getWinner().equals(bet.get(1))
                            && poker.getWinner() != 2
                            && !(poker.getWinner() == 0
                            && poker.getBankerPoint() == 6)) {
                        amount -= chip;
                        chip = 50;
                        strategy2335();
                        lost++;
                        if (amount<50)
                            return;
                    }
                    break;
//                case 213:
//                    if (poker.getWinner().equals(bet.get(0))) {
//                        amount += chip;
//                        chip = 500;
//                        time = 215;
//                        if (amount >= 5500)
//                            return;
//                    } else if (!poker.getWinner().equals(bet.get(0))
//                            && poker.getWinner() != 2
//                            && !(poker.getWinner() == 0
//                            && poker.getBankerPoint() == 6)) {
//                        amount -= chip;
//                        lost++;
//                        strategy2335();
//                        if (amount <= 2100) {
//                            time = 215;
//                            chip = 500;
//                        }
//                    }
//                    break;
//                case 215:
//                    if (poker.getWinner().equals(bet.get(1))) {
//                        amount += chip;
//                        chip = 300;
//                        time = 213;
//                        win++;
//                        strategy2335();
//                    } else if (!poker.getWinner().equals(bet.get(1))
//                            && poker.getWinner() != 2
//                            && !(poker.getWinner() == 0
//                            && poker.getBankerPoint() == 6)) {
//                        amount -= chip;
//                        lost++;
//                        strategy2335();
//                        if (amount <= 2100)
//                            time = 225;
//                    }
//                    break;
//                case 225:
//                    if (poker.getWinner().equals(bet.get(0))) {
//                        amount += chip;
//                        chip = 800;
//                        time = 228;
//                    } else if (!poker.getWinner().equals(bet.get(0))
//                            && poker.getWinner() != 2
//                            && !(poker.getWinner() == 0
//                            && poker.getBankerPoint() == 6)) {
//                        amount -= chip;
//                        lost++;
//                        strategy2335();
//                        if (amount < 500)
//                            return;
//                    }
//                    break;
//                case 228:
//                    if (poker.getWinner().equals(bet.get(1))) {
//                        amount += chip;
//                        chip = 300;
//                        time = 213;
//                        strategy2335();
//                        win++;
//                        if (amount >= 5500)
//                            return;
//                    } else if (!poker.getWinner().equals(bet.get(1))
//                            && poker.getWinner() != 2
//                            && !(poker.getWinner() == 0
//                            && poker.getBankerPoint() == 6)) {
//                        amount -= chip;
//                        chip = 500;
//                        strategy2335();
//                        lost++;
//                        if (amount < 500)
//                            return;
//                    }
//                    break;
            }
            if (max < amount)
                max = amount;
            if (count>=79)
                return;
            if (amount>=550)
                return;
        }
    }
}
